package UF_ZIP;

import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Example {
    public static final void copy(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int len;

        while ((len = in.read(buffer)) >= 0) {
            out.write(buffer, 0, len);
        }

        in.close();
        out.close();
    }

    public final void unzip(final ZipFile zipFile) {
        Enumeration entries;
        entries = zipFile.entries();

        try {
            while (entries.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) entries.nextElement();

                if (entry.isDirectory()) {
                    final File dir = new File(entry.getName());
                    dir.mkdir();
                } else {
                    try {
                        copy(zipFile.getInputStream(entry), new FileOutputStream(entry.getName()));
                    } catch (IOException e) {
                        zipFile.close();
                    }
                }
            }

            zipFile.close();
        } catch (IOException e) {
            // do nothing
        }
    }
}
